package com.nacrtstudio.webgiftshop.pages;

import java.text.SimpleDateFormat;

import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.nacrtstudio.webgiftshop.facade.Controller;
import com.nacrtstudio.webgiftshop.model.shop.Order;
import com.nacrtstudio.webgiftshop.model.shop.PackedGift;
import com.nacrtstudio.webgiftshop.model.shop.User;

public class UserProfile {
	@Inject
	private Controller controller;
	
	@Property
	private User user;
	@Property
	private Order order;
	@Property
	private PackedGift packedGift;

	
	private void onActivate() {
		try {
			user = controller.getLoggedUser();
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	
	public boolean isLoggedIn(){
		return controller.isLoggedIn();
	}
	
	public boolean isAddressNull(){
		if (user.getAddress()==null) {
			return false;
		}
		return true;
	}
	
	public boolean isBDateNull(){
		if (user.getDateOfBirth()==null) {
			return false;
		}
		return true;
	}
	
	public boolean isPhoneNull(){
		if (user.getPhoneNumber()==null) {
			return false;
		}
		return true;
	}	
	
	public String getCountry(){
		return user.getAddress().getCountry().name();
	}
	
	public String getFormatedDate(){
		return new SimpleDateFormat("d MMM. yyy").format(user.getDateOfBirth());
	}
	@InjectPage
	private GiftInfo giftInfo;
	Object onActionFromShow(Long id){
		giftInfo.setGift(controller.findGift(id));
    	return giftInfo;
    }
}
